<template>
	<view class="address-manage rf-row-wrapper">
		<view class="row b-b">
			<text class="tit">联系人</text>
			<input
				class="input"
				type="text"
				v-model="form.customerUserName"
				@blur="handleRealNameChange"
				placeholder="收货人姓名"
				placeholder-class="placeholder"
			/>
		</view>
		<view class="row b-b">
			<text class="tit">手机号</text>
			<input
				class="input"
				type="number"
				v-model="form.shippingPhone"
				@blur="handleMobileChange"
				placeholder="收货人手机号码"
				placeholder-class="placeholder"
			/>
		</view>
		<view class="row b-b" @click="aaaa()">
			<text class="tit">选择地址</text>
			<!--地址三级联动-->
			<u-picker mode="region" v-model="show" @confirm="abcd"></u-picker>
			{{form.selector}}
		</view>
		<view class="row b-b">
			<text class="tit">详细地址</text>
			<input
				class="input"
				type="text"
				v-model="form.address"
				@blur="bindAddressDetailsChange"
				placeholder="请输入详细地址"
				placeholder-class="placeholder"
			/>
		</view>
		<view class="row default-row">
			<text class="tit">设为默认</text>
			<switch
				:checked="form.isDefault ? 1 : 0"
				:color="themeColor.color"
				@change="switchChange"
			/>
		</view>
		<button
			class="add-btn"
			:class="'bg-' + themeColor.name"
			:disabled="btnLoading"
			:loading="btnLoading"
			@click="confirm"
		>
			提交
		</button>
	
		<!--加载动画-->
		<rfLoading isFullScreen :active="loading"></rfLoading>
	</view>
</template>

<script>
	import { addressCreate, addressUpdate, addressDetail } from '@/api/userInfo';
	import rfPickRegions from '@/components/rf-pick-regions/index.vue';
	export default {
		components: {
			rfPickRegions
		},
		data(){
			return{
				form:{
					beforeUserId:'',
					customerUserName:'',
					shippingPhone:'',	
					selector:'',
					address:'',
					isDefault:0,			
				},		
				btnLoading: false,
				loading: false,
				show:false,
			}
		},
		onLoad(options) {
			this.form = JSON.parse(decodeURIComponent(options.to));
			uni.getStorage({
				key:'beforeUser',
				success: (res) => {
					this.beforeUserId=res.data.beforeUserId
				}
			})
			console.log(this.form)
		},
		methods:{
			aaaa(){
			    this.show = true	
				console.log(1111)
			},
			abcd(data){
				this.form.selector = data.province.label +"-"+ data.city.label +"-"+ data.area.label
			},
			confirm(){
				this.form.beforeUserId=this.beforeUserId;
				this.btnLoading = true;
				uni.request({
					url: 'http://localhost:9090/before/bgs/customer-addr/TowUpdateAddress', 
					data: {
						addressData: this.form
					},
					method: 'POST',
					success: (res) => {				
						console.log("修改成功")		
						this.btnLoading = false;
						this.$mRouter.push({
							route: `/pages/user/address/address`
						});
					}
				});
			}
		}
	}
</script>

<style>
 .from {
	 margin-top: 10px;
	 background-color: #FFFFFF;
 }
 .item {
	 padding-left: 20px;
 }
.row {
	margin-top: 10px;
	background-color: #FFFFFF;
	height: 60px;
	width: 415px;
	float :right
}
.tit {
	float :right
}
.button {
	margin-top: 20px;
	
}
</style>
